include ../../makedef.mk

libsrc := $(wildcard *.c)
libtarget := $(patsubst %.c,%.o,${libsrc})

GCCFLAGS := ${GCCFLAGS} -Wno-analyzer-malloc-leak -fdevirtualize-at-ltrans 

CFLAGS := ${CFLAGS} -D_GNU_SOURCE -fno-builtin-malloc -fno-exceptions -DRUNTIME_DBG_LVL=0
CPPFLAGS := -D_GNU_SOURCE 

SOFLAGS := -fPIC -shared -ftls-model=initial-exec


LIBINC := -I../../include/ -I../../include_api/ -I../../include_arch/ -I../../include_plat/

.PHONY:clean all run

all:$(libtarget)
	@rm -f *.plist


clean:
	rm ../preproc_lib/*.o.c -f 
	rm ../build_lib/*.o -f
	rm ../build_lib/*.a -f
	rm ../build_lib/*.so -f
	
%.o:%.c
	@mkdir -p ../build_lib
	@mkdir -p ../preproc_lib
	@echo "----generated pre-processed $@.cpp----"
	@${GCC} ${LIBINC} ${PREDEFINED}  $^ -E  > ../preproc_lib/g$@.c
	@${CLANG} ${LIBINC} ${PREDEFINED}  $^ -E  > ../preproc_lib/cl$@.c
	@echo "----run clang static analyzer----"
	@${CLANG} ${LIBINC} ${PREDEFINED}  --analyze $^
	@#echo "----compiling static lib using gcc with analyzer----"
	@#${GCC} ${LIBINC} ${PREDEFINED}  $^ ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -c -o ../build_lib/glib$*malloc.a
	@#echo "----compiling static lib using clang----"
	@#${CLANG} ${LIBINC} ${PREDEFINED}  $^ ${COPT_FLAGS} ${CFLAGS}  -c -o ../build_lib/cllib$*malloc.a
	@echo "----compiling dynamic lib using gcc with analyzer ../build_lib/glib$*malloc.so----"
	@${GCC} ${SOFLAGS} ${PREDEFINED}  ${LIBINC} $^ ${COPT_FLAGS} ${CFLAGS} ${GCCFLAGS} -o ../build_lib/glib$*malloc.so
	@echo "----compiling dynamic lib using clang ../build_lib/cllib$*malloc.so----"
	@${CLANG} ${SOFLAGS} ${PREDEFINED}  ${LIBINC} $^ ${COPT_FLAGS} ${CFLAGS} -o ../build_lib/cllib$*malloc.so
